package com.kmxd.ams.app.event.message;

import com.kmxd.ams.app.event.message.command.SendMessageCmd;
import com.kmxd.ams.client.event.message.MessageNoticeEvent;
import com.kmxd.ams.client.event.message.MessageSysEvent;
import com.kmxd.ams.client.event.message.MessageTodoEvent;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * 消息发送监听
 *
 * @author ZuoLG
 */
@Slf4j
@Component
@AllArgsConstructor
public class MessageListener {

  private final SendMessageCmd sendMessageCmd;

  /**
   * 发送待办消息
   *
   * @param event
   * @throws Exception
   */
  @Async
  @TransactionalEventListener(fallbackExecution = true)
  public void sendTodoMsg(MessageTodoEvent event) throws Exception {
    sendMessageCmd.sendTodoMsg(event);
  }

  /**
   * 发送系统消息
   *
   * @param event
   * @throws Exception
   */
  @Async
  @TransactionalEventListener(fallbackExecution = true)
  public void sendSysMsg(MessageSysEvent event) throws Exception {
    sendMessageCmd.sendSysMsg(event);
  }

  /**
   * 发送通知消息
   *
   * @param event
   * @throws Exception
   */
  @Async
  @TransactionalEventListener(fallbackExecution = true)
  public void sendNoticeMsg(MessageNoticeEvent event) throws Exception {
    sendMessageCmd.sendNoticeMsg(event);
  }
}
